const mongoose = require('mongoose')
const { dbUri } = require('../config/config.default')
mongoose.connect(dbUri, {
  useNewUrlParser: true,
  useUnifiedTopology: true
})
// 创建数据库链接
const db = mongoose.connection
// 当连接失败时
db.on('error', err => {
  console.log(`数据库连接失败，${err}`)
})
// 当连接成功时
db.once('open', () => {
  console.log('数据库连接成功')
})

// 导出模型类
module.exports = {
  User: mongoose.model('User', require('./user')),
  Article: mongoose.model('Article', require('./article')),
  Profile: mongoose.model('Profile', require('./profile')),
  Tag: mongoose.model('Tag', require('./tag'))
}
